package com.docmanage.web.controller.am;

import com.docmanage.am.domain.AmAuthRole;
import com.docmanage.am.service.impl.AmAuthRoleService;
import com.docmanage.common.core.controller.BaseController;
import com.docmanage.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 按角色授权Controller
 * 
 * @author pointLion
 * @date 2023-07-10
 */
@RestController
@RequestMapping("/am/authRole")
public class AmAuthRoleController extends BaseController
{
    @Autowired
    private AmAuthRoleService amAuthRoleService;

    ///**
    // * 查询按角色授权列表
    // */
    //@PreAuthorize("@ss.hasPermi('am:authRole:list')")
    //@GetMapping("/list")
    //public TableDataInfo list(AmAuthRole amAuthRole)
    //{
    //    startPage();
    //    List<AmAuthRole> list = amAuthRoleService.selectAmAuthRoleList(amAuthRole);
    //    return getDataTable(list);
    //}


    ///**
    // * 导出按角色授权列表
    // */
    //@PreAuthorize("@ss.hasPermi('am:authRole:export')")
    //@Log(title = "按角色授权", businessType = BusinessType.EXPORT)
    //@PostMapping("/export")
    //public void export(HttpServletResponse response, AmAuthRole amAuthRole)
    //{
    //    List<AmAuthRole> list = amAuthRoleService.selectAmAuthRoleList(amAuthRole);
    //    ExcelUtil<AmAuthRole> util = new ExcelUtil<AmAuthRole>(AmAuthRole.class);
    //    util.exportExcel(response, list, "按角色授权数据");
    //}
    //
    ///**
    // * 获取按角色授权详细信息
    // */
    //@PreAuthorize("@ss.hasPermi('am:authRole:query')")
    //@GetMapping(value = "/{id}")
    //public AjaxResult getInfo(@PathVariable("id") Long id)
    //{
    //    return AjaxResult.success(amAuthRoleService.selectAmAuthRoleById(id));
    //}
    //
    ///**
    // * 新增按角色授权
    // */
    //@PreAuthorize("@ss.hasPermi('am:authRole:add')")
    //@Log(title = "按角色授权", businessType = BusinessType.INSERT)
    //@PostMapping
    //public AjaxResult add(@RequestBody AmAuthRole amAuthRole)
    //{
    //    return toAjax(amAuthRoleService.insertAmAuthRole(amAuthRole));
    //}
    //
    ///**
    // * 修改按角色授权
    // */
    //@PreAuthorize("@ss.hasPermi('am:authRole:edit')")
    //@Log(title = "按角色授权", businessType = BusinessType.UPDATE)
    //@PutMapping
    //public AjaxResult edit(@RequestBody AmAuthRole amAuthRole)
    //{
    //    return toAjax(amAuthRoleService.updateAmAuthRole(amAuthRole));
    //}
    //
    ///**
    // * 删除按角色授权
    // */
    //@PreAuthorize("@ss.hasPermi('am:authRole:remove')")
    //@Log(title = "按角色授权", businessType = BusinessType.DELETE)
	//@DeleteMapping("/{ids}")
    //public AjaxResult remove(@PathVariable Long[] ids)
    //{
    //    return toAjax(amAuthRoleService.deleteAmAuthRoleByIds(ids));
    //}


    /****
     * 按照 角色ID查询，该角色下的所有文件夹权限
     * @param roleId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('am:authRole:list')")
    @GetMapping("/listAuthFolder/{roleId}")
    public AjaxResult listAuthFolder(@PathVariable("roleId") Long roleId)
    {
        List<AmAuthRole> list = amAuthRoleService.listAuthFolder(roleId);
        return AjaxResult.success(list);
    }


    /****
     * 给文件夹授权
     * @param auth
     * @return
     */
    @PostMapping("/allotFolder")
    public AjaxResult allotFolder(@RequestBody AmAuthRole auth){
        amAuthRoleService.allotFolder(auth);
        return success();
    }
}
